/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.toolkit;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.web.util.HtmlUtils;
import org.springframework.web.util.JavaScriptUtils;

public class CustomFilter {

    private static String[] forbidden = {

    "违禁词1", "违禁词2", "违禁词3", "违禁词4", "违禁词5" };

    public static String customFilter(String original) {

        if (original != null) {

            StringBuffer changed = new StringBuffer(original);

            changed = new StringBuffer(HtmlUtils.htmlEscape(changed.toString()));
            changed = new StringBuffer(changed.toString().replaceAll("&amp;",
                    "&"));

            for (int i = 0; i < forbidden.length; i++) {
                changed = new StringBuffer(changed.toString().replaceAll(
                        forbidden[i], "****"));
            }
            // changed = new
            // StringBuffer(JavaScriptUtils.javaScriptEscape(changed.toString()));
            // changed = new
            // StringBuffer(StringEscapeUtils.escapeSql(changed.toString()));
            return changed.toString();

        }
        return original;

    }

}